import request, { RequestDto } from './request'
import { UserInfoDto } from '@/store/user'

export interface LoginParams {
  email: string
  password: string
}
export interface CreateUserParams extends LoginParams {
  nickName: string
}

export interface UpdateUserInfoParams {
  _id: string
  avatar?: string
  nickName?: string
  description?: string
}
// 新建账号
export function createUser(data: CreateUserParams): Promise<RequestDto<UserInfoDto>> {
  return request.post('/users', data)
}
//登录
export function loginAccount(data: LoginParams): Promise<RequestDto<{ token: string }>> {
  return request.post('/user/login', data)
}
// 获取当前用户信息
export function getCurrentUserInfo(): Promise<RequestDto<UserInfoDto>> {
  return request.get('/user/current')
}
// 更新用户信息
export function updateUserInfo(data: UpdateUserInfoParams): Promise<RequestDto<UserInfoDto>> {
  return request.patch(`/user/${data._id}`, data)
}
